package com.puman.watchtrade.fragment.home.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.puman.watchtrade.R;
import com.puman.watchtrade.fragment.home.imageLoader.util.UniversalImageLoadTool;
import com.puman.watchtrade.fragment.home.model.Varieties;
import com.puman.watchtrade.util.ImageDownloader;
import com.puman.watchtrade.util.OnImageDownload;

public class VarietiesTodayListViewAdapter extends BaseAdapter {

	private LayoutInflater listContainer; // ��ͼ����
	private View view;
	private Activity activity;
	private ImageDownloader mDownloader;
	private Varieties varieties = new Varieties();

	public final class ListItemView {
		public TextView title;
		public TextView endtime;
		public ImageView image;
	}

	public VarietiesTodayListViewAdapter(Activity activity, Varieties varieties) {
		this.activity = activity;
		this.varieties = varieties;
		listContainer = LayoutInflater.from(activity);
		// TODO Auto-generated constructor stub
	}

	/**
	 */
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ListItemView listItemView;
		final int selectID = position;
		if (convertView == null) {
			listItemView = new ListItemView();
			convertView = listContainer.inflate(R.layout.varieties_item, null);
			listItemView.title = (TextView) convertView
					.findViewById(R.id.info_title);
			listItemView.endtime = (TextView) convertView
					.findViewById(R.id.varieties_endtime);
			listItemView.image = (ImageView) convertView
					.findViewById(R.id.info_item_image);
			convertView.setTag(listItemView);
		} else {
			listItemView = (ListItemView) convertView.getTag();

		}
		if (varieties.varietiesList.get(position).getTitle().length() > 20) {
			listItemView.title.setText(varieties.varietiesList.get(position)
					.getTitle().substring(0, 20)
					+ "...");
		} else {
			listItemView.title.setText(varieties.varietiesList.get(position)
					.getTitle());
		}
		listItemView.endtime.setText(varieties.varietiesList.get(position)
				.getEndTimeString());
		String urlString = varieties.varietiesList.get(position).getImgUrl()
				.replace(" ", "");
		if (!urlString.equals("")) {
			UniversalImageLoadTool.display(urlString, (ImageView) listItemView.image,
					R.drawable.load_default);
		}

		return convertView;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return varieties.varietiesList.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub

		return 0;
	}

}